// components/activity/activity-owner-view/index.js
import componentBehavior from '../../../behaviors/component';
import { COMPONENT_OPTIONS } from '../../../constants/common';
import { COMMON_PAGE } from '../../../constants/route';
import { ACTIVITY_OWNER_VALUE } from '../../../constants/activity';
import { navTo, callPhone } from '../../../common/env';
import { getPicFullPath } from '../../../common/utils';

Component({
    behaviors: [componentBehavior],
    options: {
        ...COMPONENT_OPTIONS,
    },
    properties: {
        type: {
            type: String,
            value: 'detail', // detail || preview
        },
        ownerInfo: {
            type: Object,
            value: {},
        },
        activityInfo: {
            type: Object,
            value: {},
        },
    },
    observers: {
        'activityInfo, ownerInfo': function(val, val1) {
            const pic = val ? val.ownerPic || val1.pic : val1.pic;
            (val || val1) && this.setData({ avatarUrl: getPicFullPath(pic) });
        },
    },
    data: {
        avatarUrl: '',
    },
    methods: {
        handleCallPhone(e) {
            if (this.data.type === 'preview') return;
            const { tel } = this.data.activityInfo;
            callPhone(tel);
        },
        handleNavTo() {
            if (this.data.type === 'preview') return;
            const { owner, brandId, storeId, pubUserId } = this.data.activityInfo;
            if (owner === ACTIVITY_OWNER_VALUE.brand) {
                navTo(COMMON_PAGE['shareBrand'], {
                    brandId,
                });
            } else if (owner === ACTIVITY_OWNER_VALUE.store) {
                navTo(COMMON_PAGE['shareStore'], {
                    storeId,
                });
            } else if (owner === ACTIVITY_OWNER_VALUE.spokesman) {
                navTo(COMMON_PAGE['shareUser'], {
                    userId: pubUserId,
                });
            }
        },
    }
})

